package cn.chencaiju.day08;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import org.junit.Test;

public class TreeMapTest {
	public void traverseTreeMap(Map<String,String> treeMap) {
		Set<Entry<String, String>> entrySet = treeMap.entrySet();
		for(Entry<String,String> entry:entrySet) {
			System.out.println(entry.getKey()+"\t"+entry.getValue());
		}
	}
	@Test public void testTraverse() {
		Map<String,String> treeMap=new TreeMap<>();
		treeMap.put("递归", "recursion");
		treeMap.put("优化", "optimize");
		treeMap.put("可读性", "readability");
		traverseTreeMap(treeMap);
		Map<Car,Integer> tree=new TreeMap<>();
		tree.put(new Car("红旗",4.2f,1.8f), 1);
		tree.put(new Car("红旗",4,1.8f), 2);
		tree.put(new Car("红旗",4.3f,1.8f), 3);
		Set<Entry<Car, Integer>> entrySet = tree.entrySet();
		for(Entry<Car,Integer> item:entrySet) {
			System.out.println(item.getKey()+"\t"+item.getValue());
		}
	}
}
